

package com.thxrinfo.operate.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.thxrinfo.operate.api.entity.Merchant;
import com.thxrinfo.operate.service.MerchantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 商户表
 *
 * @author ct
 * @date 2023-03-06 15:07:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/merchant" )
@Tag(name = "商户表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class MerchantController {

    private final MerchantService merchantService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param merchant 商户表
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('operate_merchant_get')" )
    public R getMerchantPage(Page page, Merchant merchant) {
        return R.ok(merchantService.page(page, merchant));
    }


    /**
     * 通过id查询商户表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('operate_merchant_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(merchantService.getById(id));
    }

    /**
     * 新增商户表
     * @param merchant 商户表
     * @return R
     */
    @Operation(summary = "新增商户表", description = "新增商户表")
    @SysLog("新增商户表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('operate_merchant_add')" )
    public R save(@RequestBody Merchant merchant) {
        return R.ok(merchantService.saveMerchant(merchant));
    }

    /**
     * 修改商户表
     * @param merchant 商户表
     * @return R
     */
    @Operation(summary = "修改商户表", description = "修改商户表")
    @SysLog("修改商户表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('operate_merchant_edit')" )
    public R updateById(@RequestBody Merchant merchant) {
		return R.ok(merchantService.updateById(merchant));
    }

    /**
     * 通过id删除商户表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id删除商户表", description = "通过id删除商户表")
    @SysLog("通过id删除商户表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('operate_merchant_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(merchantService.removeById(id));
    }

}
